//
//  DeviceHomeViewController.m
//  Fantasia
//
//  Created by kongkong on 16/9/30.
//  Copyright © 2016年 Kongkong. All rights reserved.
//

#import "DeviceHomeViewController.h"
#import "DeviceInfoViewController.h"
#import "DeviceStatusViewController.h"
#import "DeviceParameterViewController.h"
#import "OtherViewController.h"

@interface DeviceHomeViewController()<UITabBarControllerDelegate>

@end

@implementation DeviceHomeViewController

- (void)viewDidLoad{
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    
    self.delegate = self;
    [self loadTabbarControllers];
    
    [self loadTabbarItems];
    
    //设置初始状态选中的下标
    self.selectedIndex = 0;
}

- (void)loadTabbarControllers{
    
    DeviceInfoViewController* info = [[DeviceInfoViewController alloc]init];
    info.title = self.title;
    info.tabBarItem = [[UITabBarItem alloc]initWithTitle:@"设备信息" image:[UIImage imageNamed:@"info"] tag:0];
    
    DeviceStatusViewController* status = [[DeviceStatusViewController alloc]init];
    status.title = self.title;
    status.tabBarItem = [[UITabBarItem alloc]initWithTitle:@"设备状态" image:[UIImage imageNamed:@"status"] tag:1];
    
    DeviceParameterViewController* param = [[DeviceParameterViewController alloc]init];
    param.title = self.title;
    param.tabBarItem = [[UITabBarItem alloc]initWithTitle:@"本机参数" image:[UIImage imageNamed:@"parameter"] tag:2];
    
    OtherViewController* other = [[OtherViewController alloc]init];
    other.title = self.title;
    other.tabBarItem = [[UITabBarItem alloc]initWithTitle:@"其他" image:[UIImage imageNamed:@"other"] tag:3];
    
    [self setViewControllers:@[info,status,param,other] animated:YES];
}

- (void)loadTabbarItems{
    
    self.tabBar.tintColor = [UIColor orangeColor];
    
    //设置标签栏的颜色
    self.tabBar.barTintColor = [UIColor blackColor];
    
    //设置标签栏风格(默认高度49)
    self.tabBar.barStyle = UIBarStyleBlack;
    self.tabBar.translucent = YES;
}

- (void)viewWillAppear:(BOOL)animated{
    NSMutableArray* items = [NSMutableArray array];
    if (self.selectedViewController.rightButtons) {
        [items addObjectsFromArray:self.selectedViewController.rightButtons];
    }
    [self.navigationItem setRightBarButtonItems:items];
}

- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController{
    NSMutableArray* items = [NSMutableArray array];
    if (viewController.rightButtons) {
        [items addObjectsFromArray:viewController.rightButtons];
    }
    [self.navigationItem setRightBarButtonItems:items];
    return YES;
}

@end
